package com.UI
{
	import com.*;
	import com.Engine.*;
	import com.Home.*;
	import com.Packet.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.external.*;
	import flash.filters.*;
	import flash.geom.*;
	import flash.system.*;
	import flash.text.*;
	import flash.ui.*;
	import flash.utils.*;
	
	import org.aswing.*;
	import org.aswing.border.*;
	import org.aswing.border.EmptyBorder;
	import org.aswing.colorchooser.*;
	import org.aswing.dnd.*;
	import org.aswing.event.*;
	import org.aswing.ext.*;
	import org.aswing.geom.*;
	import org.aswing.tree.AbstractLayoutCache;
	
	public class FrameCopy extends JFrame
	{
		//members define
		private var panelTop:JPanel;
		private var panelTopButtons:JPanel;
		private var btn_copy_tab_single:JToggleButton;
		private var btn_copy_tab_multi:JToggleButton;
		private var panelItems:JPanel;
		private var txtDesc:MultilineLabel;
		private var panelRewardItems:JPanel;
		private var panelBottom:JPanel;
		private var btn_copy_jump:JButton;
		private var btn_copy_enter:JButton;
		private var panelBCenter:JPanel;
		private var btnPrev:JButton;
		private var labelPage:JLabel;
		private var btnNext:JButton;
		private var labelName:JLabel;
		//-----------------------------------
		private var btn_close:JButton;
		public function FrameCopy()
		{
			//component creation
			super();
			setResizable(false);
			setBackgroundDecorator(null);
			setBorder(new EmptyBorder());
			
			//component creation
			setSize(new IntDimension(645, 403));
			setPreferredSize(new IntDimension(645, 403));
			var layout0:EmptyLayout = new EmptyLayout();
			getContentPane().setLayout(layout0);
			
			panelTop = new JPanel();
			panelTop.setLocation(new IntPoint(0, 8));
			panelTop.setSize(new IntDimension(645, 25));
			panelTop.setPreferredSize(new IntDimension(645, 25));
			var layout1:FlowWrapLayout = new FlowWrapLayout();
			layout1.setPreferWidth(200);
			layout1.setAlignment(AsWingConstants.LEFT);
			layout1.setHgap(20);
			layout1.setVgap(0);
			layout1.setMargin(true);
			panelTop.setLayout(layout1);
			
			panelTopButtons = new JPanel();
			panelTopButtons.setLocation(new IntPoint(2, 0));
			panelTopButtons.setSize(new IntDimension(600, 25));
			panelTopButtons.setPreferredSize(new IntDimension(600, 25));
			var layout2:FlowWrapLayout = new FlowWrapLayout();
			layout2.setPreferWidth(200);
			layout2.setAlignment(AsWingConstants.LEFT);
			layout2.setHgap(2);
			layout2.setVgap(0);
			layout2.setMargin(true);
			panelTopButtons.setLayout(layout2);
			
			btn_copy_tab_single = new JToggleButton();
			btn_copy_tab_single.setLocation(new IntPoint(5, 5));
			btn_copy_tab_single.setSize(new IntDimension(77, 25));
			btn_copy_tab_single.setPreferredSize(new IntDimension(77, 25));
			btn_copy_tab_single.setText("label");
			
			btn_copy_tab_multi = new JToggleButton();
			btn_copy_tab_multi.setLocation(new IntPoint(87, 5));
			btn_copy_tab_multi.setSize(new IntDimension(77, 25));
			btn_copy_tab_multi.setPreferredSize(new IntDimension(77, 25));
			btn_copy_tab_multi.setText("label");
			
			panelItems = new JPanel();
			panelItems.setLocation(new IntPoint(9, 36));
			panelItems.setSize(new IntDimension(492, 293));
			panelItems.setPreferredSize(new IntDimension(492, 293));
			var layout3:GridLayout = new GridLayout();
			layout3.setRows(2);
			layout3.setColumns(3);
			layout3.setHgap(0);
			layout3.setVgap(3);
			panelItems.setLayout(layout3);
			
			txtDesc = new MultilineLabel();
			txtDesc.setLocation(new IntPoint(502, 52));
			txtDesc.setSize(new IntDimension(136, 129));
			txtDesc.setPreferredSize(new IntDimension(136, 129));
			
			panelRewardItems = new JPanel();
			panelRewardItems.setLocation(new IntPoint(504, 190));
			panelRewardItems.setSize(new IntDimension(136, 136));
			panelRewardItems.setPreferredSize(new IntDimension(136, 136));
			var layout4:GridLayout = new GridLayout();
			layout4.setRows(3);
			layout4.setColumns(3);
			layout4.setHgap(1);
			layout4.setVgap(1);
			panelRewardItems.setLayout(layout4);
			
			panelBottom = new JPanel();
			panelBottom.setLocation(new IntPoint(502, 333));
			panelBottom.setSize(new IntDimension(136, 26));
			panelBottom.setPreferredSize(new IntDimension(136, 26));
			var layout5:FlowWrapLayout = new FlowWrapLayout();
			layout5.setPreferWidth(200);
			layout5.setAlignment(AsWingConstants.CENTER);
			layout5.setHgap(10);
			layout5.setVgap(0);
			panelBottom.setLayout(layout5);
			
			btn_copy_jump = new JButton();
			btn_copy_jump.setLocation(new IntPoint(5, 5));
			btn_copy_jump.setSize(new IntDimension(51, 26));
			btn_copy_jump.setPreferredSize(new IntDimension(51, 26));
			btn_copy_jump.setText("label");
			
			btn_copy_enter = new JButton();
			btn_copy_enter.setLocation(new IntPoint(61, 5));
			btn_copy_enter.setSize(new IntDimension(51, 26));
			btn_copy_enter.setPreferredSize(new IntDimension(51, 26));
			btn_copy_enter.setText("label");
			
			panelBCenter = new JPanel();
			panelBCenter.setLocation(new IntPoint(203, 334));
			panelBCenter.setSize(new IntDimension(104, 24));
			panelBCenter.setPreferredSize(new IntDimension(104, 24));
			var layout6:FlowWrapLayout = new FlowWrapLayout();
			layout6.setPreferWidth(200);
			layout6.setAlignment(AsWingConstants.CENTER);
			layout6.setHgap(5);
			layout6.setVgap(0);
			layout6.setMargin(false);
			panelBCenter.setLayout(layout6);
			
			btnPrev = new JButton();
			btnPrev.setLocation(new IntPoint(5, 5));
			btnPrev.setSize(new IntDimension(31, 23));
			btnPrev.setPreferredSize(new IntDimension(29, 24));
			btnPrev.setText("label");
			
			labelPage = new JLabel();
			labelPage.setLocation(new IntPoint(34, 4));
			labelPage.setSize(new IntDimension(36, 16));
			labelPage.setPreferredSize(new IntDimension(36, 16));
			labelPage.setText("label");
			
			btnNext = new JButton();
			btnNext.setLocation(new IntPoint(69, 0));
			btnNext.setSize(new IntDimension(31, 23));
			btnNext.setPreferredSize(new IntDimension(29, 24));
			btnNext.setText("label");
			
			labelName = new JLabel();
			labelName.setLocation(new IntPoint(502, 32));
			labelName.setSize(new IntDimension(136, 20));
			labelName.setPreferredSize(new IntDimension(136, 20));
			labelName.setText("label");
			
			//component layoution
			getContentPane().append(panelTop);
			getContentPane().append(panelItems);
			getContentPane().append(txtDesc);
			getContentPane().append(panelRewardItems);
			getContentPane().append(panelBottom);
			getContentPane().append(panelBCenter);
			getContentPane().append(labelName);
			
			panelTop.append(panelTopButtons);
			
			panelTopButtons.append(btn_copy_tab_single);
			panelTopButtons.append(btn_copy_tab_multi);
			
			panelBottom.append(btn_copy_jump);
			panelBottom.append(btn_copy_enter);
			
			panelBCenter.append(btnPrev);
			panelBCenter.append(labelPage);
			panelBCenter.append(btnNext);
			
			//---------------------------------------------
			
			btn_close = new JButton();
			btn_close.setLocation(new IntPoint(198, -5));
			btn_close.setSize(new IntDimension(27, 27));
			btn_close.setPreferredSize(new IntDimension(27, 27));
			getTitleBar().setCloseButton(btn_close);
			getTitleBar().setMinimizeHeight(32);
			
			btn_copy_tab_single.addActionListener(onBtnTabSingle);
			btn_copy_tab_multi.addActionListener(onBtnTabMulti);
			
			setImages();
		}
		
		private var _currentPageIndex:int = 0;
		private var _currentPageIndexAll:int = 0;
		private var _itemsPerPage:int = 6;
		public function updatePage():void
		{
			var obj:Object = null;
			for each(obj in _mallItems)
			{
				obj.item = null;
			}
			var array:Array = [];
			for each(obj in Client._CopyCSV)
			{
				if(int(obj.type) == copyType)
					array.push(obj);
			}
			var nIndex:int = 0;
			var nCount:int = 0;
			for each(var item:Object in array)
			{
				nCount++;
				if(nCount <= _currentPageIndex*_itemsPerPage)
					continue;
				_mallItems[nIndex++].item = item;
				if(nIndex >= _itemsPerPage)
					break;
			}
			
			var nCount1:int = array.length;
			_currentPageIndexAll = Math.floor((nCount1+_itemsPerPage-1)/_itemsPerPage);
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
			btnPrev.setEnabled(_currentPageIndex > 0 &&  _currentPageIndexAll > 1);
			btnNext.setEnabled(_currentPageIndex < _currentPageIndexAll-1 &&  _currentPageIndexAll > 1);
		}
		
		private function onBtnPrev(event:Event):void
		{
			_currentPageIndex--;
			if(_currentPageIndex < 0)
				_currentPageIndex = 0;
			else
				updatePage();
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
		}
		private function onBtnNext(event:Event):void
		{
			_currentPageIndex++;
			if(_currentPageIndex > _currentPageIndexAll-1)
				_currentPageIndex = _currentPageIndexAll-1;
			else
				updatePage();
			labelPage.setText(_currentPageIndex+1+'/'+_currentPageIndexAll);
		}
		private var copyType:int = 0;
		private function onBtnTabSingle(e:Event):void
		{
			copyType = 0;
			updatePage();
		}
		private function onBtnTabMulti(e:Event):void
		{
			copyType = 1;
			updatePage();
		}
		private var _mallItems:Array = new Array();
		private var _mallRewardItems:Array = new Array();
		public function setImages():void
		{
			var img_copy_bg:AssetBackground  = new AssetBackground(Client.getUIElement("img_copy_bg") as DisplayObject);
			var img_char_background:DisplayObject = img_copy_bg.getDisplay(null);
			setBackgroundDecorator(img_copy_bg);
			setSizeWH(img_char_background.width,img_char_background.height);
			setLocationXY((Engine.W - width)/2,(Engine.H - height)/2);
			btn_copy_tab_single.setSelected(true);
			
			btn_copy_tab_single.setText("");
			btn_copy_tab_multi.setText("");
			btn_copy_tab_single.wrapSimpleButton(Client.getUIElement("btn_copy_tab_single") as SimpleButton);
			btn_copy_tab_multi.wrapSimpleButton(Client.getUIElement("btn_copy_tab_multi") as SimpleButton);
			
			btn_copy_jump.setText("");
			btn_copy_jump.wrapSimpleButton(Client.getUIElement("btn_copy_jump") as SimpleButton);
			
			btn_copy_enter.setText("");
			btn_copy_enter.wrapSimpleButton(Client.getUIElement("btn_copy_enter") as SimpleButton);

			btn_copy_jump.setEnabled(false);
			btn_copy_enter.setEnabled(false);
			
			
			var group:ButtonGroup = new ButtonGroup();
			group.appendAll(btn_copy_tab_single,btn_copy_tab_multi);
			
			btn_close.wrapSimpleButton(Client.getUIElement("btn_close") as SimpleButton);
			
			var font:ASFont = null;//new ASFont("宋体", 14, true, false, false, false);
			var filter:GlowFilter = null;
			btnPrev.wrapSimpleButton(Client.getUIElement("btn_prev") as SimpleButton);
			btnNext.wrapSimpleButton(Client.getUIElement("btn_next") as SimpleButton);
			btnPrev.setText("");
			btnNext.setText("");
			btnPrev.addActionListener(onBtnPrev);
			btnNext.addActionListener(onBtnNext);
			font = new ASFont("宋体", 12, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelPage.setForeground(ASColor.WHITE);
			labelPage.setFont(font);
			labelPage.setTextFilters(new Array(filter));
			txtDesc.setForeground(ASColor.WHITE);
			txtDesc.filters = new Array(filter);
			txtDesc.setFont(new ASFont("宋体", 13, false, false, false, false));
			for(var i:int = 0; i < _itemsPerPage; i++)
			{
				var item:PaneCopyItem = new PaneCopyItem;
				panelItems.append(item);
				_mallItems.push(item);
			}
			
			for(var j:int = 0; j < 9; j++)
			{
				var itemCSV:PanelItemCSV = new PanelItemCSV;
				panelRewardItems.append(itemCSV);
				_mallRewardItems.push(itemCSV);
			}
			
			font = new ASFont("宋体", 14, false, false, false, false);
			filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			labelName.setForeground(ASColor.ORANGE);
			labelName.setFont(font);
			labelName.setTextFilters(new Array(filter));
			
			labelName.setText("");
			
			//var filter:GlowFilter;
			//var font:ASFont = new ASFont("宋体", 14, true, false, false, false);
			//filter = new GlowFilter(0x000000, 1, 2, 2, 10);
			//labelLevel.setFont(font);
			//labelLevel.setForeground(ASColor.WHITE);
			//labelLevel.setTextFilters(new Array(filter));
			getContentPane().setClipMasked(false);
			setClipMasked(false);
			panelTop.setClipMasked(false);
			panelBottom.setClipMasked(false);
			panelRewardItems.setClipMasked(false);
			panelTopButtons.setClipMasked(false);
			panelItems.setClipMasked(false);
		}
		public function selectItem(item:Object):void
		{
			labelName.setText("");
			txtDesc.setHtmlText("");
			var i:int = 0;
			for(i = 0; i < 9; i++)
			{
				(_mallRewardItems[i] as PanelItemCSV).item = null;
			}
			if(item == null)
				return;
			labelName.setText(item.name);
			txtDesc.setHtmlText("    "+item.description);
			var dtemp:Array = (item.reward_items as String).split(';');
			var array:Array = [];
			for(i = 0; i < dtemp.length; i++)
			{
				var obj:Object = Client.getInstance().GetItemCSV(int(dtemp[i]));
				(_mallRewardItems[i] as PanelItemCSV).item = obj;
				if(i >= 9)
					break;
			}
			btn_copy_jump.setEnabled(true);
			btn_copy_enter.setEnabled(true);
		}
		public static var _frame:FrameCopy = null;
		public static function show():void
		{
			if(isShowing())
			{
				_frame.hide();
				return;
			}
			if(_frame == null)
			{
				_frame = new FrameCopy();
				PanelMainHelp.getInstance().addChild(_frame);
			}
			_frame.show();
			PanelMainHelp.getInstance().bringToTop(_frame);
			_frame.updatePage();
			
		}
		public static function hide():void
		{
			if(isShowing())_frame.hide();
		}
		public static function isShowing():Boolean
		{
			return(_frame != null&& _frame.isShowing());
		}
	}
}
import com.*;
import com.Engine.*;
import com.Home.*;
import com.Packet.*;
import com.UI.*;

import flash.display.*;
import flash.events.*;
import flash.external.*;
import flash.filters.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;

import org.aswing.*;
import org.aswing.border.*;
import org.aswing.border.EmptyBorder;
import org.aswing.colorchooser.*;
import org.aswing.dnd.*;
import org.aswing.event.*;
import org.aswing.ext.*;
import org.aswing.geom.*;
import org.aswing.tree.AbstractLayoutCache;

/**
 * MyPaneCopyItem
 */
class PaneCopyItem extends JPanel{
	
	//members define
	
	/**
	 * MyPaneCopyItem Constructor
	 */
	
	//members define
	private var labelName:JLabel;
	private var panelImage:JPanel;
	private var labelLevel:JLabel;
	private var labelCount:JLabel;
	
	public function PaneCopyItem(){
		//component creation
		setSize(new IntDimension(164, 145));
		setPreferredSize(new IntDimension(164, 145));
		var layout0:EmptyLayout = new EmptyLayout();
		setLayout(layout0);
		
		labelName = new JLabel();
		labelName.setLocation(new IntPoint(26, 4));
		labelName.setSize(new IntDimension(107, 20));
		labelName.setPreferredSize(new IntDimension(107, 20));
		labelName.setText("label");
		
		panelImage = new JPanel();
		panelImage.setLocation(new IntPoint(1, 27));
		panelImage.setSize(new IntDimension(159, 72));
		panelImage.setPreferredSize(new IntDimension(159, 72));
		
		labelLevel = new JLabel();
		labelLevel.setLocation(new IntPoint(1, 100));
		labelLevel.setSize(new IntDimension(159, 20));
		labelLevel.setPreferredSize(new IntDimension(159, 20));
		labelLevel.setText("label");
		
		labelCount = new JLabel();
		labelCount.setLocation(new IntPoint(1, 121));
		labelCount.setSize(new IntDimension(159, 20));
		labelCount.setPreferredSize(new IntDimension(159, 20));
		labelCount.setText("label");
		
		//component layoution
		append(labelName);
		append(panelImage);
		append(labelLevel);
		append(labelCount);
		
		//component layoution
		var img_char_background:DisplayObject = Client.getUIElement("img_copy_item_bg") as DisplayObject;
		setBackgroundDecorator(new AssetBackground(img_char_background));
		setSizeWH(img_char_background.width,img_char_background.height);
		
		addEventListener(MouseEvent.ROLL_OVER, onRollOver);
		addEventListener(MouseEvent.ROLL_OUT, onRollOut);
		addEventListener(ClickCountEvent.CLICK_COUNT, onItemClickCount);
		
		var font:ASFont = new ASFont("宋体", 14, false, false, false, false);
		var filter:GlowFilter = null;
		filter = new GlowFilter(0x000000, 1, 2, 2, 10);
		labelName.setForeground(ASColor.ORANGE);
		labelName.setFont(font);
		labelName.setTextFilters(new Array(filter));
		
		font = new ASFont("宋体", 12, false, false, false, false);
		labelLevel.setForeground(ASColor.GREEN);
		labelLevel.setFont(font);
		labelLevel.setTextFilters(new Array(filter));
		
		labelCount.setForeground(ASColor.WHITE);
		labelCount.setFont(font);
		labelCount.setTextFilters(new Array(filter));
		
		labelName.setText("打屁之厅");
		labelLevel.setText("等级要求:100");
		labelCount.setText("今日次数:3/5");
		
	}
	
	private var filterArray:Array = new Array(new GlowFilter(0xFFFF00, 1, 2, 2, 5));
	private function onRollOver(event:MouseEvent):void
	{
		if(filters != filterArray)
			filters = filterArray;
		if(this.parent is Container)
			(this.parent as Container).bringToTop(this);
	}
	
	private function onRollOut(event:MouseEvent):void
	{
		//filters = null;
		filters = _selected ? filterArray :null;
	}
	static public var selectedItem:PaneCopyItem = null;
	private function onItemClickCount(event:ClickCountEvent):void
	{   
		if(event.getCount() >= 1)
		{   
			if(selectedItem != null)
			{
				selectedItem.selected = false;
				selectedItem = null;
			}
			selectedItem = this;
			selectedItem.selected = true;
			FrameCopy._frame.selectItem(_item);
		}   
			
	}
	public var _selected:Boolean = false;
	public function set selected(val:Boolean):void
	{
		_selected = val;
		filters = _selected ? filterArray :null;
	}
	//_________getters_________
	//_________getters_________
	private var _item:Object = null;
	private var _loaderSmall:LoaderData = null;
	public function set item(val:Object):void
	{
		_item = val;
		labelName.setText("");
		panelImage.setBackgroundDecorator(null);
		labelLevel.setText("");
		labelCount.setText("");
		
		if(_item == null)
		{
			return;
		}
		labelName.setText(_item.name);
		
		var objTask:Object = Client.getInstance().GetTaskCSV(int(_item.task_id));
		if(objTask != null)
		{
			//if(objTask.require_level > CharInfo.m_nLevel)
			labelLevel.setForeground(objTask.require_level > CharInfo.m_nLevel ? ASColor.RED : ASColor.GREEN);
			labelLevel.setText("等级要求: " + objTask.require_level);
			labelCount.setText("今日次数: " + (FrameTask._arCountEveryday[int(_item.task_id)] != null ? FrameTask._arCountEveryday[int(_item.task_id)] : '0')+'/'+ objTask.count_everyday);
		}
		
		if(_smallMap != null)
		{
			_smallMap.dispose();
			_smallMap = null;
		}
		
		if(_loaderSmall != null)
		{
			_loaderSmall.unloadAndStop();
			_loaderSmall = null;
		}
		// 读取地图缩略
		_loaderSmall = new LoaderData();
		_loaderSmall.contentLoaderInfo.addEventListener(Event.COMPLETE,onSmallMapLoaded);
		_loaderSmall.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,onSmallMapLoadedError);
		_loaderSmall.load(new URLRequest(Engine.assetMapPath+_item.image_id+'/small.png'));
		panelImage.pack();
		panelImage.paintImmediately();
		pack();
		this.paintImmediately();
	}
	protected var _smallMap:BitmapData;
	private function onSmallMapLoadedError(e:IOErrorEvent):void
	{
		var loadinfo:LoaderInfo = e.target as LoaderInfo;
		var loader:LoaderData = loadinfo.loader as LoaderData;
		loadinfo.removeEventListener(Event.COMPLETE,onSmallMapLoaded);
		loadinfo.removeEventListener(IOErrorEvent.IO_ERROR,onSmallMapLoadedError);
		
		if(_loaderSmall != null)
		{
			_loaderSmall.unloadAndStop();
			_loaderSmall = null;
		}
		else
		{
			loader.unloadAndStop();
			loader = null;
		}
	}
	
	/**
	 * 缩略图加载完成
	 */ 
	private function onSmallMapLoaded(e:Event):void
	{
		var loadinfo:LoaderInfo = e.target as LoaderInfo;
		var loader:LoaderData = loadinfo.loader as LoaderData;
		
		loadinfo.removeEventListener(Event.COMPLETE,onSmallMapLoaded);
		loadinfo.removeEventListener(IOErrorEvent.IO_ERROR,onSmallMapLoadedError);
		if(_loaderSmall != null)
		{
			if(_smallMap != null)
			{
				_smallMap.dispose();
				_smallMap = null;
			}
			_smallMap = (loadinfo.content as Bitmap).bitmapData;
			panelImage.setBackgroundDecorator(new AssetBackground(new Bitmap(_smallMap)));
			panelImage.pack();
			panelImage.paintImmediately();
			pack();
			paintImmediately();
		}
		else
		{
			loader.unloadAndStop();
			loader = null;
		}
	}
	
	public function get item():Object
	{
		return _item;
	}
	
}